from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views

# 创建路由器并注册视图集
router = DefaultRouter()
router.register(r'boms', views.BillOfMaterialsViewSet)
router.register(r'bom-components', views.BOMComponentViewSet)
router.register(r'bom-versions', views.BOMVersionViewSet)
router.register(r'alternative-materials', views.AlternativeMaterialViewSet)
router.register(r'bom-documents', views.BOMDocumentViewSet)

# API URL配置
urlpatterns = [
    path('', include(router.urls)),
    
    # 自定义API端点
    path('boms/<int:pk>/calculate-cost/', views.BillOfMaterialsViewSet.as_view({'post': 'calculate_cost'})),
    path('boms/<int:pk>/clone/', views.BillOfMaterialsViewSet.as_view({'post': 'clone'})),
    path('boms/<int:pk>/change-status/', views.BillOfMaterialsViewSet.as_view({'patch': 'change_status'})),
    path('boms/<int:pk>/export/', views.BillOfMaterialsViewSet.as_view({'get': 'export'})),
    path('boms/import/', views.BillOfMaterialsViewSet.as_view({'post': 'import_data'})),
    path('boms/template/', views.BillOfMaterialsViewSet.as_view({'get': 'download_template'})),
    path('boms/product-boms/', views.BillOfMaterialsViewSet.as_view({'get': 'get_product_boms'})),
    path('boms/active-bom/', views.BillOfMaterialsViewSet.as_view({'get': 'get_active_bom'})),
    
    path('bom-components/batch-add/', views.BOMComponentViewSet.as_view({'post': 'batch_add'})),
    path('bom-components/batch-update/', views.BOMComponentViewSet.as_view({'post': 'batch_update'})),
    
    path('bom-versions/<int:pk>/activate/', views.BOMVersionViewSet.as_view({'post': 'activate'})),
]